package ar.edu.ufasta.presupuestos.servicios.web.netpacks;

import java.util.StringTokenizer;

import ar.edu.ufasta.presupuestos.servicios.web.Constantes;

public class LoginRequest extends RequestPack {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * 
	 */
	
	/**
	 * 
	 */
	
	private String usuario;
	private String password;

	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * @return the usuario
	 */
	public String getUsuario() {
		return usuario;
	}

	/**
	 * @param password
	 *            the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * @param usuario
	 *            the usuario to set
	 */
	public void setUsuario(String usuario) {
		this.usuario = usuario;
	}

	@Override
	public void codificarTrama() {
		trama = "";
		trama = trama + protocol + ";";
		trama = trama + systemCode + ";";
		trama = trama + operationCode + ";";
		trama = trama + usuario + ";";
		trama = trama + password + ";";
		int checksum = trama.length()+1;
		trama = trama + Integer.toString(checksum) + ";";
		trama = trama + "\n";		
	}

	@Override
	public void decodificarTrama() {
		StringTokenizer st = new StringTokenizer(trama,";");
		st.countTokens();
		try {
			protocol = Integer.valueOf(st.nextToken());
			systemCode = Integer.valueOf(st.nextToken());
			operationCode = Integer.valueOf(st.nextToken());
			usuario = st.nextToken();
			password = st.nextToken();
		} catch (Exception e) {
			protocol = Constantes.PROTOCOL_100;
			systemCode = Constantes.SYSTEM_CODE;
			operationCode = 999;
		}			
	}

}
